package com.activity.exg4pcd;

import com.ui.exg4pcd.R;
import com.ui.exg4pcd.TablActivity;

import domain.businessEntity.cardinfo.CardInfo;
import domain.businessService.cardinfo.CardService;
import domain.businessService.cardinfo.ICardService;
import foundation.data.DataHelper;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EditActivity extends Activity {
	public ICardService service;
  public CardInfo tempcard=new CardInfo();
	Button btn_save;
	EditText edname;
	EditText edsex;
	EditText edphone;
	EditText edemail;
	EditText edqq;
	EditText edweibo;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_edit);
		service=new CardService();
		tempcard=service.getCardInfo(0);
		edname=(EditText) findViewById(R.id.editname);
		edsex=(EditText) findViewById(R.id.editsex);
		 edphone=(EditText) findViewById(R.id.editphone);
		edemail=(EditText) findViewById(R.id.editemail);
		edqq=(EditText) findViewById(R.id.editqq);
		edweibo=(EditText) findViewById(R.id.editweibo);
		btn_save=(Button) findViewById(R.id.btn_Save);
		 
			edname.setText(tempcard.getName().toString());
			edsex.setText(tempcard.getSex().toString());
			edphone.setText(tempcard.getPhone().toString());
			 edemail.setText(tempcard.getEmail().toString());
			 edqq.setText(tempcard.getQQ().toString());
			 edweibo.setText(tempcard.getWeibo().toString());
			 
			 btn_save.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					 //TODO Auto-generated method stub
					tempcard.setName(edname.getText().toString());
					tempcard.setSex(edsex.getText().toString());
					tempcard.setPhone(edphone.getText().toString());
					tempcard.setQQ(edqq.getText().toString());
					tempcard.setEmail(edemail.getText().toString());
					tempcard.setWeibo(edweibo.getText().toString());
					service.updateMyCardInfo(tempcard);
					Intent intent=new Intent(EditActivity.this,TablActivity.class);
					startActivity(intent);
				}
			});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.edit, menu);
		return true;
	}

}
